<?php
function xlsBOF() {
    echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
    return;
}

function xlsEOF() {
    echo pack("ss", 0x0A, 0x00);
    return;
}

function xlsWriteNumber($Row, $Col, $Value) {
    echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
    echo pack("d", $Value);
    return;
}

function xlsWriteLabel($Row, $Col, $Value ) {
    $L = strlen($Value);
    
    echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
    echo $Value;
return;
}




    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");;
    header("Content-Disposition: attachment;filename=Research_Data.xls "); // à¹à¸¥à¹‰à¸§à¸™à¸µà¹ˆà¸à¹‡à¸Šà¸·à¹ˆà¸­à¹„à¸Ÿà¸¥à¹Œ
    header("Content-Transfer-Encoding: binary ");

    // XLS Data Cell

                xlsBOF();
                xlsWriteLabel(1,3,"Research Data");
                xlsWriteLabel(3,0,"Sr.No");
                xlsWriteLabel(3,1,"Citation");
                xlsWriteLabel(3,2,"Contributor");
                xlsWriteLabel(3,3,"Observation Date");
                xlsWriteLabel(3,4,"Observation Time");
                xlsWriteLabel(3,5,"Location");
                xlsWriteLabel(3,6,"Lat");
                xlsWriteLabel(3,7,"Lng");
                xlsWriteLabel(3,8,"Depth");
                xlsWriteLabel(3,9,"Species");
                xlsWriteLabel(3,10,"Quantity");
                xlsWriteLabel(3,11,"Unit");
                
                $xlsRow = 4;
                foreach($researchs as $r)
                {
                      ++$i;
                      xlsWriteNumber($xlsRow, 0, $i);
                      xlsWriteLabel($xlsRow, 1, $r->Observationdepth->Observation->Research["citation"]);
                      xlsWriteLabel($xlsRow, 2, $r->Observationdepth->Observation->Research->Entity["firstname"]);
                      xlsWriteLabel($xlsRow, 3, $r->Observationdepth->Observation["observationdate"]);
                      xlsWriteLabel($xlsRow, 4, $r->Observationdepth->Observation["observationtime"]);
                      xlsWriteLabel($xlsRow, 5, $r->Observationdepth->Observation["location"]);
                      xlsWriteLabel($xlsRow, 6, $r->Observationdepth->Observation["lat"]);
                      xlsWriteLabel($xlsRow, 7, $r->Observationdepth->Observation["lng"]);
                      xlsWriteLabel($xlsRow, 8, $r->Observationdepth["observationdepth"]);
                      xlsWriteLabel($xlsRow, 9, $r->Species["species"]);
                      xlsWriteLabel($xlsRow, 10, $r->getQuantity());
                      xlsWriteLabel($xlsRow, 11, $r->Species->Unit["unit"]);
                      $xlsRow++;
                }

                     xlsEOF();
                 exit();
?>